/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.util.List;
import model.Elev;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import util.HibernateUtil;

/**
 *
 * @author Marc
 */
public class ElevControl {
    public ElevControl(){
        
    }
    

    public Elev[] getElever(){    
     Session session = HibernateUtil.getSessionFactory().openSession();
    Elev[] elever = null;
        String hql = "";
        try {
            hql = "from Elev";
            session.beginTransaction();
            Query q = session.createQuery(hql);
            List resultList = q.list();
            elever = new Elev[resultList.size()]; 
            for (int i = 0; i < resultList.size(); i++) {
                
                elever[i] = (Elev) resultList.get(i);
            }
            session.getTransaction().commit();
            
        } catch (HibernateException he) {
            System.out.println(he.getLocalizedMessage());
        }
        
        return elever;
    }
}
